﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMK.Framework.Model;
using XMK.Tadong.Data;
using XMK.Utils;
using XMK.Tadong.Model;
using XMK.Tadong.Model.Cond;

namespace XMK.Tadong.Biz
{
    public class Base_DictBiz
    {
        /// <summary>
        /// 字典类型编辑
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public ResponseInfo EditDictType(Base_DictTypeCond cond)
        {
            ResponseInfo response = null;
            try
            {
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (bool)data.EditDictType(cond);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[EditDictType:]" + ex.ToString());
            }
            return response;

        }

        public ResponseInfo GetDictType(int dicttypeid)
        {
            ResponseInfo response = null;
            try
            {
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (Base_DictTypeInfo)data.GetDictType(dicttypeid);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[GetDictType:]" + ex.ToString());
            }
            return response;

        }

        public ResponseInfo IsExistDictType(Base_DictTypeCond cond)
        {
            ResponseInfo response = null;
            try
            {
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (bool)data.IsExistDictType(cond);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[IsExistDictType:]" + ex.ToString());
            }
            return response;

        }

        /// <summary>
        /// 字典类型列表
        /// </summary>
        /// <returns></returns>
        public ResponseInfo QueryDictType(PageInfo pageInfo, OrderInfo order)
        {
            ResponseInfo response = null;
            try
            {
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (List<Base_DictTypeInfo>)data.QueryDictType(pageInfo, order);
                response.Page = pageInfo;
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[QueryDictType:]" + ex.ToString());
            }
            return response;

        }

        public ResponseInfo QueryDictItemList(int DICTTYPE_ID, PageInfo pageInfo, OrderInfo order)
        {
            ResponseInfo response = null;
            try
            {
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (List<Base_DictItemInfo>)data.QueryDictItemList(DICTTYPE_ID, pageInfo, order);
                response.Page = pageInfo;
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[QueryDictItemList:]" + ex.ToString());
            }
            return response;

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="DICTTYPE_ID"></param>
        /// <returns></returns>
        public ResponseInfo QueryDictItemList2(int DICTTYPE_ID)
        {
            ResponseInfo response = null;
            try
            {
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (List<Base_DictItemInfo>)data.QueryDictItemList2(DICTTYPE_ID);
                
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[QueryDictItemList2:]" + ex.ToString());
            }
            return response;

        }

        public ResponseInfo EditDictItem(Base_DictItemCond cond)
        {
            ResponseInfo response = null;
            try
            {
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (bool)data.EditDictItem(cond);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[EditDictItem:]" + ex.ToString());
            }
            return response;

        }

        /// <summary>
        /// 表导出权限
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public ResponseInfo SaveTableAuthority(Base_TableAuthorityCond cond)
        {
            ResponseInfo response = null;
            try
            {
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (bool)data.SaveTableAuthority(cond);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[EditDictItem:]" + ex.ToString());
            }
            return response;

        }
        

        public ResponseInfo QueryDictTableList( PageInfo pageInfo, OrderInfo order)
        {
            ResponseInfo response = null;
            try
            {
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (List<Dict_TableInfo>)data.QueryDictTableList(pageInfo, order);
                response.Page = pageInfo;
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[QueryDictTableList:]" + ex.ToString());
            }
            return response;

        }

        /// <summary>
        /// 结构化表权限
        /// </summary>
        /// <param name="pageInfo"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        public ResponseInfo QueryDictTableRoleList(string roleId,PageInfo pageInfo, OrderInfo order)
        {
            ResponseInfo response = null;
            try
            {
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (List<Dict_TableInfo>)data.QueryDictTableRoleList(roleId,pageInfo, order);
                response.Page = pageInfo;
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[QueryDictTableRoleList:]" + ex.ToString());
            }
            return response;

        }


        /// <summary>
        /// 结构化表
        /// </summary>
        /// <returns></returns>
        public ResponseInfo QueryDictTableList2()
        {
            ResponseInfo response = null;
            try
            {
                return new Base_DictBiz().QueryDictTableList(new PageInfo() { CurrentPage = 1, PageSize = int.MaxValue }, new OrderInfo());
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[QueryDictTableList:]" + ex.ToString());
            }
            return response;

        }

        public ResponseInfo QueryDictTableRoleSave(Base_StrcutRoleCond cond)
        {
            ResponseInfo response = null;
            try
            {
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (bool)data.QueryDictTableRoleSave(cond);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[QueryDictTableRoleSave:]" + ex.ToString());
            }
            return response;

        }

        /// <summary>
        /// 是否有权限下载,结构化表
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public ResponseInfo GetUserStructTableRight(Base_StructTableRightCond cond)
        {
            ResponseInfo response = null;
            try
            {
                cond.UserId = LoginUserBiz.LoginUserID();
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (bool)data.GetUserStructTableRight(cond);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[QueryDictTableRoleSave:]" + ex.ToString());
            }
            return response;

        }
        /// <summary>
        /// 是否有文档操作权限
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public ResponseInfo GetUserFileRoleRight(Base_FileRoleOper cond)
        {
            ResponseInfo response = null;
            try
            {
                cond.UserId = LoginUserBiz.LoginUserID();
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                response = new ResponseInfo();
                if ((bool)data.GetUserAreaRoleRight(cond))//判断用户范围权限
                    response.Data = (bool)data.GetUserFileRoleRight(cond);
                else
                    response.Data = false;  
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[GetUserFileRoleRight:]" + ex.ToString());
            }
            return response;

        }
        /// <summary>
        /// 文件集合是否有文档操作权限
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public ResponseInfo GetUserFileRoleRightList(Base_FileRoleOper cond)
        {
            ResponseInfo response = null;
            Base_FileRoleOper cond1 = new Base_FileRoleOper();
            try
            {
                string str1 = "";
                cond.UserId = LoginUserBiz.LoginUserID();
                response = new ResponseInfo();
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                string[] str = cond.FileId.Split(',');
                for (int i = 0; i < str.Length; i++)
                {
                    cond1.FileId = str[i];
                    cond1.UserId = cond.UserId;
                    cond1.SpaceType = cond.SpaceType;
                    cond1.OpreType = cond.OpreType;
                    if (data.GetUserFileRoleRight(cond1) == true)
                    {
                        str1 += str[i]+ ",";
                    }
                   
                }
                response.Data = str1;  
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[GetUserFileRoleRight:]" + ex.ToString());
            }
            return response;

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public ResponseInfo GetCurTableInfoByTableCode(string table_code)
        {
            ResponseInfo response = null;
            try
            {
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (Dict_TableInfo)data.GetCurTableInfoByTableCode(table_code);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[GetCurTableInfoByTableCode:]" + ex.ToString());
            }
            return response;

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public ResponseInfo GetCurrentFileOpre(string roles_id)
        {
            ResponseInfo response = null;
            try
            {
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (Base_FileRoleRightCond)data.GetCurrentFileOpre(roles_id);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[GetCurrentFileOpre:]" + ex.ToString());
            }
            return response;

        }

        /// <summary>
        /// 获取结构化业务表列表
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public ResponseInfo QueryStructTableProList(PageInfo pageInfo, OrderInfo order)
        {
            ResponseInfo response = null;
            try
            {
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (List<Base_StructTableProCond>)data.QueryStructTableProList(pageInfo, order);
                response.Page = pageInfo;
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[QueryStructTableProList:]" + ex.ToString());
            }
            return response;

        }

        /// <summary>
        /// 获取结构业务表
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public ResponseInfo GetStructTablePro(int id)
        {
            ResponseInfo response = null;
            try
            {
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (Base_StructTableProCond)data.GetStructTablePro(id);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[GetDictType:]" + ex.ToString());
            }
            return response;

        }
        /// <summary>
        /// 编辑结构化表业务
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public ResponseInfo EditStructTablePro(Base_StructTableProCond cond)
        {
            ResponseInfo response = null;
            try
            {
                Base_DictData data = new Base_DictData(Config.TadongDbProvider);
                response = new ResponseInfo();
                response.Data = (bool)data.EditStructTablePro(cond);
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[GetDictType:]" + ex.ToString());
            }
            return response;

        }

    }
}
